﻿using System;
using Microsoft.EntityFrameworkCore.Migrations;

#nullable disable

namespace HengTong.DataAccess.Migrations
{
    /// <inheritdoc />
    public partial class 新增班次班组多对多关系表 : Migration
    {
        /// <inheritdoc />
        protected override void Up(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.DropForeignKey(
                name: "FK_SysAttendanceShift_SysAttendanceShiftGroup_GroupId",
                table: "SysAttendanceShift");

            migrationBuilder.DropIndex(
                name: "IX_SysAttendanceShift_GroupId",
                table: "SysAttendanceShift");

            migrationBuilder.DropColumn(
                name: "GroupId",
                table: "SysAttendanceShift");

            migrationBuilder.CreateTable(
                name: "SysAttendanceShiftAndGroup",
                columns: table => new
                {
                    ID = table.Column<Guid>(type: "uniqueidentifier", nullable: false),
                    ShiftId = table.Column<Guid>(type: "uniqueidentifier", nullable: false),
                    GroupId = table.Column<Guid>(type: "uniqueidentifier", nullable: false)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_SysAttendanceShiftAndGroup", x => x.ID);
                    table.ForeignKey(
                        name: "FK_SysAttendanceShiftAndGroup_SysAttendanceShiftGroup_GroupId",
                        column: x => x.GroupId,
                        principalTable: "SysAttendanceShiftGroup",
                        principalColumn: "ID",
                        onDelete: ReferentialAction.Cascade);
                    table.ForeignKey(
                        name: "FK_SysAttendanceShiftAndGroup_SysAttendanceShift_ShiftId",
                        column: x => x.ShiftId,
                        principalTable: "SysAttendanceShift",
                        principalColumn: "ID",
                        onDelete: ReferentialAction.Cascade);
                });

            migrationBuilder.CreateIndex(
                name: "IX_SysAttendanceShiftAndGroup_GroupId",
                table: "SysAttendanceShiftAndGroup",
                column: "GroupId");

            migrationBuilder.CreateIndex(
                name: "IX_SysAttendanceShiftAndGroup_ShiftId",
                table: "SysAttendanceShiftAndGroup",
                column: "ShiftId");
        }

        /// <inheritdoc />
        protected override void Down(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.DropTable(
                name: "SysAttendanceShiftAndGroup");

            migrationBuilder.AddColumn<Guid>(
                name: "GroupId",
                table: "SysAttendanceShift",
                type: "uniqueidentifier",
                nullable: true);

            migrationBuilder.CreateIndex(
                name: "IX_SysAttendanceShift_GroupId",
                table: "SysAttendanceShift",
                column: "GroupId");

            migrationBuilder.AddForeignKey(
                name: "FK_SysAttendanceShift_SysAttendanceShiftGroup_GroupId",
                table: "SysAttendanceShift",
                column: "GroupId",
                principalTable: "SysAttendanceShiftGroup",
                principalColumn: "ID");
        }
    }
}
